package com.mmp.main.servlet.report;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mmp.common.servlet.BasicServlet;
import com.mmp.main.entity.SpInventoryContent;
import com.mmp.main.util.Enums;
import com.mmp.main.util.WebUtil;

@WebServlet(urlPatterns = { "/ViewAllSPInventoryCategories", "/ViewUnderThresholdSPInventoryCategories" })
public class ViewSPInventoryContent extends BasicServlet {

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
			IOException {

		String uri = WebUtil.getRequestUri(request);
		boolean underthresholdFlag = "ViewUnderThresholdSPInventoryCategories".equals(uri);
		String errorMsg;
		String reportTitle;

		if (underthresholdFlag) {
			errorMsg = "لا يوجد قطع غيار بالمستودع تحت الحد الأدنى";
			reportTitle = Enums.REPORT_TITLE.SP_INVENTORY_CONTENT_UNDER_THRESHOLD.getReportTitle();
		} else {
			errorMsg = "عفوا .. لم  يتم  إضافة أي قطع غيار للمستودع من خلال النظام";
			reportTitle = Enums.REPORT_TITLE.SP_INVENTORY_CONTENT.getReportTitle();
		}

		List<SpInventoryContent> spInventoryContentList = dbQueryManager.getSpInventoryContentsWithStats(
				getSessionSiteId(request), underthresholdFlag);

		if (spInventoryContentList == null || spInventoryContentList.isEmpty()) {
			announceErorrMessage(request, response, errorMsg);
			return;
		}

		request.setAttribute("spInventoryContentList", spInventoryContentList);
		viewHTMLReport(request, response, "report/ViewSPInventoryContent.jsp", reportTitle);
	}

}
